#include <STC89C5xRC.H>
#include "delay.h"
#include "key.h"
#include "timer0.h"
#include "nixie.h"


unsigned char keynum,speed;
unsigned char counter,compare;
sbit LED=P2^0;
sbit Motor=P1^0;

void main()
{
	Timer0_Init();
	compare=50;
	while(1)
	{
		keynum=key1();
		if(keynum==1)
		{
			speed++;
			if(speed>3)
			{
				speed=0;
			}
			if(speed==0){compare=0;}
			if(speed==1){compare=50;}
			if(speed==2){compare=75;}
			if(speed==3){compare=100;}
		}
		nixie(1,speed);

	}

}

//定时器中断函数模板100us
void timer0_routine() interrupt 1
{
    TL0 = 0xA4;				//设置定时初始值
    TH0 = 0xFF;				//设置定时初始值
	counter++;
	if(counter>=100)
	{
		counter=0;
	}
	if(counter<compare)
	{
		LED=0;
		Motor=1;
	}
	else
	{
		LED=1;
		Motor=0;
	}



}
